﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>员工管理</title>
    <!-- Bootstrap -->
    <link href="/CSS/bootstrap3.3.5/css/bootstrap.css" rel="stylesheet">
    <link href="/JqueryPlug/dtGrid/jquery.dtGrid.css" rel="stylesheet">
    <link href="/CSS/font-awesome-4.3.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="/CSS/Base/Button.css" rel="stylesheet">

    <link href="/CSS/Base/BaseClass.css" rel="stylesheet">
    <script src="/Scripts/jquery-1.11.2.min.js"></script>

    <script type="text/javascript" src="/JqueryPlug/layer/layer/layer.js"></script>
    <script src="/CSS/bootstrap3.3.5/js/bootstrap.js"></script>
    <script src="/Scripts/avalon.js"></script>
    <script src="/Scripts/jquery-migrate-1.1.0.min.js"></script>
    <script src="/JqueryPlug/dtGrid/jquery.dtGrid.js"></script>
    <script src="/Scripts/SZHLCommon.js"></script>
    <style>
        .White {
            color: #ffffff;
        }
    </style>
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="//cdn.bootcss.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="//cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <script type="text/javascript">
        var grid, dtoption;
        var model = avalon.define({
            $id: "YGGL",
            BranchData: [],
            BranchListData: [],
            SelDeptItem: {},
            pId: -1,
            GetUserList: function (item, event) {
                if (event) {
                    event.stopPropagation();
                }
                var deptCode = 1;
                if (item != null) {
                    deptCode = item.DeptCode;
                }
                $.getJSON('/API/SZHLAPI.ashx?Action=GETUSERBYCODE', { "P1": deptCode, P2: $("#tbSearch").val() }, function (resultData) {
                    if (resultData.ErrorMsg == "") {
                        grid.originalDatas = resultData.Result
                        grid.load()
                        model.SelDeptItem = item == null ? {} : item;
                    }
                })
            }
            ,
            EditDept: function (item, event) {
                if (event) {
                    event.stopPropagation();
                }
                var deptCode = item.DeptCode
                if ($.trim(deptCode) != "") {
                    parent.ComFunJS.winviewform("/Admin/BranchAdd.html?branchNo=" + deptCode, "修改部门", 788, 400);
                }
            }
        });
        avalon.ready(function () {
            //获取主要菜单
            dtoption = {
                lang: 'zh-cn',
                check: false,
                ajaxLoad: false,
                exportFileName: '用户列表',
                columns: [
                    { id: 'UserRealName', title: '用户名', type: 'string', columnClass: 'text-center', columnStyle: "width:100px" },
                    { id: 'UserName', title: '登录账号', type: 'string', columnClass: 'text-center', columnStyle: "width:100px" },
                    { id: 'IsUse', title: '是否启用', type: 'string', columnClass: 'text-center', columnStyle: "width:80px" },
                    { id: 'DeptName', title: '所在部门', type: 'string', columnClass: 'text-center', columnStyle: "width:130px" },
                    { id: 'DeptCode', title: '所在部门', type: 'string', columnClass: 'text-center', hide: true },
                    { id: 'zhiwu', title: '职务', type: 'string', columnClass: 'text-center', columnStyle: "width:130px" },
                    { id: 'mailbox', title: '邮箱', type: 'string', columnClass: 'text-center', columnStyle: "width:100px" },
                    {
                        id: 'option', title: '操作', type: 'string', columnClass: 'text-center', columnStyle: "width:200px", resolution: function (value, record, column, grid, dataNo, columnNo) {
                            var content = "";

                            content += '<button class="btn btn-xs btn-default" onclick="EditUser(\'' + record.UserName + '\');"><i class="fa fa-edit"></i>  编辑</button>';
                            content += ' ';
                            content += '<button class="btn btn-xs btn-danger" onclick="EditIsUse(\'' + record.UserName + '\',\'' + record.IsUse + '\');"><i class="fa fa-edit"></i> ' + (record.IsUse == 'Y' ? '禁用' : '启用') + '</button>';
                            content += ' ';
                            content += '<button class="btn btn-xs btn-danger"  onclick="DelUser(\'' + record.UserName + '\')"><i class="fa fa-trash-o"></i>  删除</button>';
                            return content;
                        }
                    }
                ],
                gridContainer: 'dtgrid',
                toolbarContainer: 'dtgridTool',
                pageSize: 10,
                pageSizeLimit: [10, 20, 50],
                tools: 'faseQuery',
                onGridComplete: function (grid) {
                    var log = '<p>表格加载完成。表格编号：' + grid.option.id + '。</p>';
                }
            };
            $.getJSON('/API/SZHLAPI.ashx?Action=GETBRANCH', { "P1": "1" }, function (resultData) {
                model.BranchData = resultData.Result;
                if (model.BranchData[0].DeptCode) {
                    pId = model.BranchData[0].DeptCode;
                    $.getJSON('/API/SZHLAPI.ashx?Action=GETUSERBYCODE', { "P1": 1 }, function (resultData) {
                        if (resultData.ErrorMsg == "") {
                            dtoption.datas = resultData.Result;
                            grid = $.fn.DtGrid.init(dtoption);
                            grid.load()
                        }
                    })
                }
            })
        })
        function EditUser(userName) {
            parent.ComFunJS.winviewform("/Admin/YGGLAdd.html?userName=" + userName, "修改员工", 788, 700);
            model.GetUserList(model.SelDeptItem.$model);
        }
        function DelUser(userName) {
            if (confirm("确定要删除" + userName + "么？")) {
                $.post("/API/SZHLAPI.ashx", { Action: "DELUSER", P1: userName },
                function (result) {
                    if ($.trim(result.ErrorMsg) != "") {
                        ComFunJS.winwarning(result.ErrorMsg);
                    }
                });
            }
            model.GetUserList(model.SelDeptItem.$model);
        }
        function EditIsUse(userName, status) {
            $.post("/API/SZHLAPI.ashx", { Action: "UPDATEUSERISUSE", P1: userName, P2: (status == "Y" ? "N" : "Y") },
              function (result) {
                  if ($.trim(result.ErrorMsg) != "") {
                      ComFunJS.winwarning(result.ErrorMsg);
                  }
                  model.GetUserList(model.SelDeptItem.$model);
              });
        }
        $(function () {
            $("#btADD").click(function () {
                parent.ComFunJS.winviewform("/Admin/BranchAdd.html", "添加部门", 788, 400);
            })
            $("#btADDGL").click(function () {
                var deptCode = model.SelDeptItem.DeptCode
                if ($.trim(deptCode) != "") {
                    parent.ComFunJS.winviewform("/Admin/YGGLAdd.html?branchNo=" + deptCode, "添加员工", 788, 700);
                }
            })
        })
    </script>
</head>
<body ms-controller="YGGL" style="background-color:white">
    <div class="container-fluid maindiv" style="margin: 20px" id="dvContent">
        <div class="row">
            <div class="col-xs-2">
                <div class="panel panel-default">
                    <!-- Default panel contents -->
                    <div class="panel-heading">神州互联 (<a style="cursor:pointer" ms-click="GetUserList(null,event)">全部人员</a>)</div>
                    <div class="panel-body">
                        <p><a href="#" id="btADD" style="  height: 34px;line-height: 34px; " class="button button-glow button-border button-rounded button-primary"><i class="fa fa-plus"></i>添加部门</a></p>
                    </div>
                    <!-- List group -->
                    <ul class="list-group">
                        <li class="list-group-item " ms-repeat-item="BranchData" ms-class="active:item.DeptCode==SelDeptItem.DeptCode" ms-attr-id="item.DeptCode" ms-click="GetUserList(item,event)"><span class="badge">{{item.userCount}}</span><span>{{item.DeptName}}</span><a href="#" id="btEdit" ms-click="EditDept(item,event)" ms-class="White:item.DeptCode==SelDeptItem.DeptCode" style=" line-height: 15px; margin-left:8px; ">修改</a></li>
                    </ul>
                </div>
            </div>
            <div class="col-xs-10">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        {{SelDeptItem.DeptName?SelDeptItem.DeptName:"全部人员"}}

                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <div class="col-xs-6">
                                <a href="#" id="btADDGL" ms-class="hidden:SelDeptItem.DeptCode==null" style="  height: 34px;line-height: 34px;" class="button button-glow button-border button-rounded button-primary"><i class="fa fa-plus"></i>添加员工</a><div class="input-group">
                                </div>
                            </div>
                            <div class="col-xs-6">
                                <div class="input-group">
                                    <div class="input-group-addon">搜索关键字</div>
                                    <input id="tbSearch" class="form-control" type="text" placeholder="姓名,部门,手机号..." />
                                    <span class="input-group-btn">
                                        <button class="btn btn-info " ms-click="GetUserList(SelDeptItem)">查询</button>
                                    </span>
                                </div>
                            </div>
                        </div>


                        <div id="dtgrid" style="margin-top:20px"></div>
                        <div id="dtgridTool" class="dt-grid-toolbar-container"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>